package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Product;
import cn.wolfcode.trip.base.domain.Question;
import cn.wolfcode.trip.base.mapper.QuestionMapper;
import cn.wolfcode.trip.base.query.QuestionQuery;
import cn.wolfcode.trip.base.service.IQuestionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class QuestionServiceImpl implements IQuestionService {
    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public PageInfo selectForList(QuestionQuery qo) {
        qo.setOrderBy("q.questionTime DESC");
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Question> list = questionMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public List<Question> listAll() {
        return questionMapper.selectAll();
    }

    @Override
    public Question get(Long id) {
        questionMapper.updateViewsNums(id);
        return questionMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveQuestion(Question question, Long questionerId) {

        questionMapper.saveQuestion(question,questionerId);
    }
}
